<?php require ('setcookie.html'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html lang="de">
<head>
    <title>MP3 Vokabeltrainer - Auffuellen - Lingomoto</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="description" content="MP3 Vokabeltrainer - Auffuellen - Sprachen lernen" />
    <meta name="language" content="de" />
    <link href="style.css" type="text/css" rel="stylesheet" />
    <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
    <script language="JavaScript">function sprung(ziel) {window.location.href=ziel;}</script>
    <script type="text/javascript">
        <!--
        function test(state){
        var checkboxes=document.getElementsByName('chosen_words[]');
        for(var n=0;n<checkboxes.length;n++){
        checkboxes[n].checked=state;
        }
        }
        -->
    </script>
</head>

<body id="trainer">

<?php
$_SESSION['logini'] = isset($_SESSION['logini']) ? $_SESSION['logini'] : false;
// read configuration
require ('konfiguration.html');
// read user-data
require ('nutzer.html');
// read header
$link = "auffuellen.html";
$langen = 'fill-learnbox.html';
$langes = 'rellenar.html';
$langru = 'fill-learnbox.html';
require ('kopf.html');
// <!-- horizontal column -->
echo '<div>';
require ('horizontal.html');
echo '</div>';
// <!-- Left Column -->
echo '<div id="left_col">';
require ('vertikal.html');
echo '</div>';

// <!-- Content -->
echo '<div id="content">';
echo '<div id="block5">';

// request for login
if ($_SESSION['logini']== false) {
    require_once ('loginformular.html'); 
}

// if new password, request for change of password
elseif ( $newpass == 1 )
{
$passwo = isset($_REQUEST['passwo']) ? $_REQUEST['passwo'] : '1';
$passwo1 = isset($_REQUEST['passwo1']) ? $_REQUEST['passwo1'] : '1';
$passwo2 = isset($_REQUEST['passwo2']) ? $_REQUEST['passwo2'] : '1';
$ok='';
require_once ('neues-passwort.html');
}
else {
// initialize variables
$key = array();
$customerid = $_SESSION['customerid'];
if ( $_SESSION['langpair'] == '' ) { $langpair = '0'; } else { $langpair = $_SESSION['langpair']; }
$change_new = isset($_REQUEST['change_new']) ? $_REQUEST['change_new'] : '';
$change_old = isset($_REQUEST['change_old']) ? $_REQUEST['change_old'] : '';
if ( $change_new <> '' ) { require_once ('newlang.html'); }
if ( $change_old <> '' ) { require_once ('oldlang.html'); }
$select1 = 0; $select2 = 0; $select3 = 0; $select4 = 0; $select5 = 0; $select6 = 0;
$chosen_words = isset($_REQUEST['chosen_words']) ? $_REQUEST['chosen_words'] : array();
$checked = isset($_REQUEST['savechecked']) ? $_REQUEST['savechecked'] : 'wordbox0';
$fillup = isset($_REQUEST['fillup']) ? $_REQUEST['fillup'] : 0;
$modus = isset($_REQUEST['modus']) ? $_REQUEST['modus'] : 1;
$negativ = isset($_REQUEST['negativ']) ? $_REQUEST['negativ'] : 0;
$zero = isset($_REQUEST['zero']) ? $_REQUEST['zero'] : 0;
$bo1 = isset($_REQUEST['bo1']) ? $_REQUEST['bo1'] : 0;
$bo2 = isset($_REQUEST['bo2']) ? $_REQUEST['bo2'] : 0;
$bo3 = isset($_REQUEST['bo3']) ? $_REQUEST['bo3'] : 0;
$bo4 = isset($_REQUEST['bo4']) ? $_REQUEST['bo4'] : 0;
$bo5 = isset($_REQUEST['bo5']) ? $_REQUEST['bo5'] : 0;
$bo6 = isset($_REQUEST['bo6']) ? $_REQUEST['bo6'] : 0;
$saveresult1 = isset($_REQUEST['saveresult1']) ? $_REQUEST['saveresult1'] : 0;
$saveresult2 = isset($_REQUEST['saveresult2']) ? $_REQUEST['saveresult2'] : 0;
$saveresult3 = isset($_REQUEST['saveresult3']) ? $_REQUEST['saveresult3'] : 0;
$saveresult4 = isset($_REQUEST['saveresult4']) ? $_REQUEST['saveresult4'] : 0;
$saveresult5 = isset($_REQUEST['saveresult5']) ? $_REQUEST['saveresult5'] : 0;
$saveresult6 = isset($_REQUEST['saveresult6']) ? $_REQUEST['saveresult6'] : 0;
$saveselect1 = isset($_REQUEST['saveselect1']) ? $_REQUEST['saveselect1'] : 0;
$saveselect2 = isset($_REQUEST['saveselect2']) ? $_REQUEST['saveselect2'] : 0;
$saveselect3 = isset($_REQUEST['saveselect3']) ? $_REQUEST['saveselect3'] : 0;
$saveselect4 = isset($_REQUEST['saveselect4']) ? $_REQUEST['saveselect4'] : 0;
$saveselect5 = isset($_REQUEST['saveselect5']) ? $_REQUEST['saveselect5'] : 0;
$saveselect6 = isset($_REQUEST['saveselect6']) ? $_REQUEST['saveselect6'] : 0;
$resultconf1 = isset($_REQUEST['resultconf1']) ? $_REQUEST['resultconf1'] : 0;
$resultconf2 = isset($_REQUEST['resultconf2']) ? $_REQUEST['resultconf2'] : 0;
$resultconf3 = isset($_REQUEST['resultconf3']) ? $_REQUEST['resultconf3'] : 0;
$resultconf4 = isset($_REQUEST['resultconf4']) ? $_REQUEST['resultconf4'] : 0;
$resultconf5 = isset($_REQUEST['resultconf5']) ? $_REQUEST['resultconf5'] : 0;
$resultconf6 = isset($_REQUEST['resultconf6']) ? $_REQUEST['resultconf6'] : 0;
$action='';
$donotchange = 0;
$savefillup = isset($_REQUEST['savefillup']) ? $_REQUEST['savefillup'] : 0;
$change = 0;
if (isset($_REQUEST['autofill_x'])) { $action = 'autofill'; $donotchange = 1; }
if (isset($_REQUEST['confirm_x'])) { $action = 'fillitup'; $donotchange = 0; }
if (isset($_REQUEST['stop_x'])) { $action = ''; }
if (isset($_REQUEST['next_x'])) { $action = ''; $donotchange = 0; $change = 1; $fillup = 0; }

$sql = "SELECT * FROM wordbox0 where boxid = 0 and customerid =". $customerid . " and langpairid =". $langpair;

// DB Query
$db_res = mysql_query( $sql );
if ( ! $db_res ) { die('Error query: ' . mysql_error()); }
$num_rows = mysql_num_rows($db_res);

// estimation of suggested number of words
if ( $num_rows < 100 )
{ $number = 100; }
if ( $num_rows < 90 )
{ $number = 90; }
if ( $num_rows < 80 )
{ $number = 80; }
if ( $num_rows < 70 )
{ $number = 70; }
if ( $num_rows < 60 )
{ $number = 60; }
if ( $num_rows < 50 )
{ $number = 60; }
if ( $num_rows < 40 )
{ $number = 60; }
if ( $num_rows < 30 )
{ $number = 60; }
if ( $num_rows < 20 )
{ $number = 60; }
if ( $num_rows < 10 )
{ $number = 60; }

// estimation of words to fill up
if ( $fillup <> 0 ) { $number = $fillup; }
$qty = $number - $num_rows;
if ( $qty < 0 ) { $qty = 0; }

// show form
$db_res = mysql_query( $sql );
if ( ! $db_res ) { die('Error query: ' . mysql_error()); }

// show actual numbers
if ( $action == 'fillitup' ) { fillitup(); }


show_dialog(); 

switch ( $action ) {
  case 'autofill' :  autofill(); break;
}

}

// ----------------------- Functions --------------------------------------------------------------------------------------------

function show_dialog() {

  global $langpair,$savefillup,$fillup,$change,$donotchange,$saveselect1,$saveselect2,$saveselect3,$saveselect4,$saveselect5,$saveselect6,$action,$modus,$checked,$db_res,$num_rows,$customerid,$qty,$number,$select1,$select2,$select3,$select4,$select5,$select6,$bo1,$bo2,$bo3,$bo4,$bo5,$bo6;

  echo '<form name="xxx" action="auffuellen.html" method="post">';

    echo '<h2>Lernbox auff&uuml;llen</h2>';
    echo '<br />';

    // Sprachen auslesen
    $sql2 = "SELECT cande,learnde,langpair FROM settings where customerid = '$customerid'";
    mysql_query('SET NAMES utf8');
    mysql_query('SET CHARACTER SET utf8');
    $db_sel2 = mysql_query_secure( $sql2 );
    while ($row = mysql_fetch_array( $db_sel2, MYSQL_ASSOC)) {
    if ( $row['cande'] == '' or $row['learnde'] == '' or $row['cande'] == '-' or $row['learnde'] == '-' )
    {
        $missinglangpair = '1';
        require_once ('sprache-waehlen.html');
    }
    else
    {

    echo '<h3>Aktuell</h3>';
    echo '<div class="content_frame">';
    echo '<div class="left2">&nbsp;</div>';
    echo '<div class="marginright2">Lernbox</div>';
    echo '<div class="marginright2">Box1</div>';
    echo '<div class="marginright2">Box2</div>';
    echo '<div class="marginright2">Box3</div>';
    echo '<div class="marginright2">Box4</div>';
    echo '<div class="marginright2">Box5</div>';
    echo '<div class="marginright2">Box6</div>';

    echo '<br />';
    echo '<div class="left2">&nbsp;</div>';
    echo '<br />';

    echo '<div class="left2">Vokabeln in Vokabelboxen:</div>';

    // actual qties in boxes 
    $sql10 = "SELECT * FROM wordbox0 where boxid = 0 and customerid =". $customerid . " and langpairid =". $langpair;
    $sql11 = "SELECT * FROM wordbox0 where boxid = 1 and customerid =". $customerid . " and langpairid =". $langpair;
    $sql12 = "SELECT * FROM wordbox0 where boxid = 2 and customerid =". $customerid . " and langpairid =". $langpair;
    $sql13 = "SELECT * FROM wordbox0 where boxid = 3 and customerid =". $customerid . " and langpairid =". $langpair;
    $sql14 = "SELECT * FROM wordbox0 where boxid = 4 and customerid =". $customerid . " and langpairid =". $langpair;
    $sql15 = "SELECT * FROM wordbox0 where boxid = 5 and customerid =". $customerid . " and langpairid =". $langpair;
    $sql16 = "SELECT * FROM wordbox0 where boxid = 6 and customerid =". $customerid . " and langpairid =". $langpair;
    $db_res0 = mysql_query( $sql10 ); if ( ! $db_res0 ) { die('Error query: ' . mysql_error()); }
    $num_rows0 = mysql_num_rows($db_res0);
    $db_res1 = mysql_query( $sql11 ); if ( ! $db_res1 ) { die('Error query: ' . mysql_error()); }
    $num_rows1 = mysql_num_rows($db_res1);
    $db_res2 = mysql_query( $sql12 ); if ( ! $db_res2 ) { die('Error query: ' . mysql_error()); }
    $num_rows2 = mysql_num_rows($db_res2);
    $db_res3 = mysql_query( $sql13 ); if ( ! $db_res3 ) { die('Error query: ' . mysql_error()); }
    $num_rows3 = mysql_num_rows($db_res3);
    $db_res4 = mysql_query( $sql14 ); if ( ! $db_res4 ) { die('Error query: ' . mysql_error()); }
    $num_rows4 = mysql_num_rows($db_res4);
    $db_res5 = mysql_query( $sql15 ); if ( ! $db_res5 ) { die('Error query: ' . mysql_error()); }
    $num_rows5 = mysql_num_rows($db_res5);
    $db_res6 = mysql_query( $sql16 ); if ( ! $db_res6 ) { die('Error query: ' . mysql_error()); }
    $num_rows6 = mysql_num_rows($db_res6);
    $summe = $num_rows1 + $num_rows2 + $num_rows3 + $num_rows4 + $num_rows5 + $num_rows6;
    
  
    echo '<div class="marginright2">'. $num_rows0 . '</div>';
    echo '<div class="marginright2">'. $num_rows1 . '</div>';
    echo '<div class="marginright2">'. $num_rows2 . '</div>';
    echo '<div class="marginright2">'. $num_rows3 . '</div>';
    echo '<div class="marginright2">'. $num_rows4 . '</div>';
    echo '<div class="marginright2">'. $num_rows5 . '</div>';
    echo '<div class="marginright2">'. $num_rows6 . '</div>';

    echo '<br />';
 
    if ( $num_rows == 100 )
    { 
        echo '<div class="left2"><b>Kein weiteres Auff&uuml;llen mehr m&ouml;glich!</b></div>'; 
    }
    else
    {
                
    echo '</div><br />';

    if ( $num_rows < 100 )
    {
        echo '<h3>Auff&uuml;llen</h3>';
        echo '<div class="content_frame">';
      /*  echo '<div>W&auml;hle, mit wieviel Prozent aus den jeweiligen Vokabelboxen aufgef&uuml;llt werden soll. Hierbei wird Deine Lernhistorie ber&uuml;cksichtigt, damit alle Vokabeln einer Vokabelbox gleichm&auml;&szlig;ig gelernt werden. Wenn nicht ausreichend Vokabeln in einer Box vorhanden sind, werden aus den anderen Vokabelboxen entsprechend mehr Vokabeln selektiert.</div>';  */

        echo '<div class="left2">&nbsp;</div>';
        echo '<div class="marginright2">Lernbox</div>';
        echo '<div class="marginright2">Box1</div>';
        echo '<div class="marginright2">Box2</div>';
        echo '<div class="marginright2">Box3</div>';
        echo '<div class="marginright2">Box4</div>';
        echo '<div class="marginright2">Box5</div>';
        echo '<div class="marginright2">Box6</div>';

        echo '<br />';
        echo '<br />';

        echo '<div class="left2"><input type="radio" id="" name="modus" value="1" class="radio" checked="checked" ></input>&nbsp;Variante 1:</div>';

        //save fillup, to see if fill-up-qty changed (see above)
        echo '<input type="hidden" name="savefillup" value="'. $fillup . '" />';

        // change of fillup?
        if ( $fillup <> $savefillup and $savefillup <> 0 ) { $change = 1; }

        echo '<select name="fillup" onchange=xxx.submit() class="marginright2" >';
        if ( $num_rows < 90 )
        { if ( $summe < 10 ) { echo '<option value="'. $summe . '" ' ; } else { echo '<option value="10"'; }
        if ( $number == 10 or $number == $summe ) { echo 'selected="selected"'; $qty = $number; }
        if ( $fillup == 0 ) { echo 'selected="selected"'; }
        if ( $summe < 10 ) { echo ' >'. $summe . '&nbsp;</option>'; } else { echo ' >10&nbsp;</option>'; } }
        if ( $num_rows < 80 and $summe > 10 )
        { if ( $summe < 20 ) { echo '<option value="'. $summe . '"'; } else { echo '<option value="20"'; }
        if ( $number == 20 or $number == $summe ) { echo 'selected="selected"'; $qty = $number; }
        if ( $fillup == 0 ) { echo 'selected="selected"'; }
        if ( $summe < 20 ) { echo ' >'. $summe . '&nbsp;</option>'; } else { echo ' >20&nbsp;</option>'; } }
        if ( $num_rows < 70 and $summe > 20 )
        { if ( $summe < 30 ) { echo '<option value="'. $summe . '"'; } else { echo '<option value="30"'; }
        if ( $number == 30 or $number == $summe ) { echo 'selected="selected"'; $qty = $number; }
        if ( $fillup == 0 ) { echo 'selected="selected"'; }
        if ( $summe < 30 ) { echo ' >'. $summe . '&nbsp;</option>'; } else { echo ' >30&nbsp;</option>'; } }
        if ( $num_rows < 60 and $summe > 30 )
        { if ( $summe < 40 ) { echo '<option value="'. $summe . '"'; } else { echo '<option value="40"'; }
        if ( $number == 40 or $number == $summe ) { echo 'selected="selected"'; $qty = $number; }
        if ( $fillup == 0 ) { echo 'selected="selected"'; }
        if ( $summe < 40 ) { echo ' >'. $summe . '&nbsp;</option>'; } else { echo ' >40&nbsp;</option>'; } }
        if ( $num_rows < 50 and $summe > 40 )
        { if ( $summe < 50 ) { echo '<option value="'. $summe . '"'; } else { echo '<option value="50"'; }
        if ( $number == 50 or $number == $summe ) { echo 'selected="selected"'; $qty = $number; }
        if ( $fillup == 0 ) { echo 'selected="selected"'; }
        if ( $summe < 50 ) { echo ' >'. $summe . '&nbsp;</option>'; } else { echo ' >50&nbsp;</option>'; } }
        if ( $num_rows < 40 and $summe > 50 )
        { if ( $summe < 60 ) { echo '<option value="'. $summe . '"'; } else { echo '<option value="60"'; }
        if ( $number == 60 or $number == $summe ) { echo 'selected="selected"'; $qty = $number; }
        if ( $fillup == 0 ) { echo 'selected="selected"'; }
        if ( $summe < 60 ) { echo ' >'. $summe . '&nbsp;</option>'; } else { echo ' >60&nbsp;</option>'; } }
        if ( $num_rows < 30 and $summe > 60 )
        { if ( $summe < 70 ) { echo '<option value="'. $summe . '"'; } else { echo '<option value="70"'; }
        if ( $number == 70 or $number == $summe ) { echo 'selected="selected"'; $qty = $number; }
        if ( $fillup == 0 ) { echo 'selected="selected"'; }
        if ( $summe < 70 ) { echo ' >'. $summe . '&nbsp;</option>'; } else { echo ' >70&nbsp;</option>'; } }
        if ( $num_rows < 20 and $summe > 70 )
        { if ( $summe < 80 ) { echo '<option value="'. $summe . '"'; } else { echo '<option value="80"'; }
        if ( $number == 80 or $number == $summe ) { echo 'selected="selected"'; $qty = $number; }
        if ( $fillup == 0 ) { echo 'selected="selected"'; }
        if ( $summe < 80 ) { echo ' >'. $summe . '&nbsp;</option>'; } else { echo ' >80&nbsp;</option>'; } }
        if ( $num_rows < 10 and $summe > 80 )
        { if ( $summe < 90 ) { echo '<option value="'. $summe . '"'; } else { echo '<option value="90"'; }
        if ( $number == 90 or $number == $summe ) { echo 'selected="selected"'; $qty = $number; }
        if ( $fillup == 0 ) { echo 'selected="selected"'; }
        if ( $summe < 90 ) { echo ' >'. $summe . '&nbsp;</option>'; } else { echo ' >90&nbsp;</option>'; } }
        if ( $num_rows < 100 and $summe > 90 )
        { if ( $summe < 100 ) { echo '<option value="'. $summe . '"'; } else { echo '<option value="100"'; }
        if ( $number == 100 or $number == $summe ) { echo 'selected="selected"'; $qty = $number; }
        if ( $fillup == 0 ) { echo 'selected="selected"'; }
        if ( $summe < 100 ) { echo ' >'. $summe . '&nbsp;</option>'; } else { echo ' >100&nbsp;</option>'; } }
        echo '</select>';


        // suggestions of words per wordbox
        if ( $modus == 1 and $donotchange <> 1 or $change == 1 )
        { 
            require_once ('autofuell.html'); 

            // save results
            echo '<input type="hidden" name="saveselect1" value="'. $select1 . '" />';
            echo '<input type="hidden" name="saveselect2" value="'. $select2 . '" />';
            echo '<input type="hidden" name="saveselect3" value="'. $select3 . '" />';
            echo '<input type="hidden" name="saveselect4" value="'. $select4 . '" />';
            echo '<input type="hidden" name="saveselect5" value="'. $select5 . '" />';
            echo '<input type="hidden" name="saveselect6" value="'. $select6 . '" />';
        }
        elseif ( $modus == 2 or $donotchange == 1 )
        { 
            // save results
            $select1 = $saveselect1;
            $select2 = $saveselect2;
            $select3 = $saveselect3;
            $select4 = $saveselect4;
            $select5 = $saveselect5;
            $select6 = $saveselect6;

            // save results
            echo '<input type="hidden" name="saveselect1" value="'. $select1 . '" />';
            echo '<input type="hidden" name="saveselect2" value="'. $select2 . '" />';
            echo '<input type="hidden" name="saveselect3" value="'. $select3 . '" />';
            echo '<input type="hidden" name="saveselect4" value="'. $select4 . '" />';
            echo '<input type="hidden" name="saveselect5" value="'. $select5 . '" />';
            echo '<input type="hidden" name="saveselect6" value="'. $select6 . '" />';
        }
        
        echo '<div class="marginright2" >'. $select1 . '</div>';
        echo '<div class="marginright2" >'. $select2 . '</div>';
        echo '<div class="marginright2" >'. $select3 . '</div>';
        echo '<div class="marginright2" >'. $select4 . '</div>';
        echo '<div class="marginright2" >'. $select5 . '</div>';
        echo '<div class="marginright2" >'. $select6 . '</div>';
        echo '<br /><br />';

        echo '<div class="left3"><input type="radio" id="" name="modus" value="2" class="radio" ';
        if ( $modus == 2 ) { echo 'checked="checked" '; }
        echo '></input>&nbsp;Variante 2:&nbsp;&nbsp;</div>';
        echo '<div class="textfield4"><input type="image" src="bilder/buttons/aktualisieren.gif" name="actualize" alt="Aktualisieren" title=" Aktualisieren " /></div>';
        
        $sumindi = $bo1 + $bo2 + $bo3 + $bo4 + $bo5 + $bo6;

        echo '<div class="textfield9" >'. $sumindi . '</div>';
        echo '<input type="text" class="textfield2" name="bo1" value="'. $bo1 . '" onClick=this.value="" ></input>';
        echo '<input type="text" class="textfield2" name="bo2" value="'. $bo2 . '" onClick=this.value="" ></input>';
        echo '<input type="text" class="textfield2" name="bo3" value="'. $bo3 . '" onClick=this.value="" ></input>';
        echo '<input type="text" class="textfield2" name="bo4" value="'. $bo4 . '" onClick=this.value="" ></input>';
        echo '<input type="text" class="textfield2" name="bo5" value="'. $bo5 . '" onClick=this.value="" ></input>';
        echo '<input type="text" class="textfield2" name="bo6" value="'. $bo6 . '" onClick=this.value="" ></input>';

        // if the results are zero
        if ( $sumindi == 0 )
        {
            $zero = 1;
            echo '<input type=hidden name=zero value='. $zero . ' />';
        }

        echo '<br /><br />';
        echo '<div class="under">&nbsp;</div>';
                                        
        echo '<div class="left2">Ergebnis nach Auff&uuml;llen:</div>';
        
        // results after filling up
        if ( $modus == 1 )
        {
            $result = $num_rows + $select1 + $select2 + $select3 + $select4 + $select5 + $select6;
            $result1 = $num_rows1 - $select1;
            $result2 = $num_rows2 - $select2;
            $result3 = $num_rows3 - $select3;
            $result4 = $num_rows4 - $select4;
            $result5 = $num_rows5 - $select5;
            $result6 = $num_rows6 - $select6;

            // save results
            echo '<input type="hidden" name="saveresult1" value="'. $select1 . '" />';
            echo '<input type="hidden" name="saveresult2" value="'. $select2 . '" />';
            echo '<input type="hidden" name="saveresult3" value="'. $select3 . '" />';
            echo '<input type="hidden" name="saveresult4" value="'. $select4 . '" />';
            echo '<input type="hidden" name="saveresult5" value="'. $select5 . '" />';
            echo '<input type="hidden" name="saveresult6" value="'. $select6 . '" />';

        }
        elseif ( $modus == 2 )
        {
            $result = $num_rows + $bo1 + $bo2 + $bo3 + $bo4 + $bo5 + $bo6;
            $result1 = $num_rows1 - $bo1;
            $result2 = $num_rows2 - $bo2;
            $result3 = $num_rows3 - $bo3;
            $result4 = $num_rows4 - $bo4;
            $result5 = $num_rows5 - $bo5;
            $result6 = $num_rows6 - $bo6;

            // save results
            echo '<input type=hidden name=saveresult1 value='. $bo1 . ' />';
            echo '<input type=hidden name=saveresult2 value='. $bo2 . ' />';
            echo '<input type=hidden name=saveresult3 value='. $bo3 . ' />';
            echo '<input type=hidden name=saveresult4 value='. $bo4 . ' />';
            echo '<input type=hidden name=saveresult5 value='. $bo5 . ' />';
            echo '<input type=hidden name=saveresult6 value='. $bo6 . ' />';
        }
            
        echo '<div class="marginright2">'. $result . '</div>';
        echo '<div class="marginright2">'. $result1 . '</div>';
        echo '<div class="marginright2">'. $result2 . '</div>';
        echo '<div class="marginright2">'. $result3 . '</div>';
        echo '<div class="marginright2">'. $result4 . '</div>';
        echo '<div class="marginright2">'. $result5 . '</div>';
        echo '<div class="marginright2">'. $result6 . '</div>';

        // if one of the results are negativ
        if ( $result1 < 0 or $result2 < 0 or $result3 < 0 or $result4 < 0 or $result5 < 0 or $result6 < 0 or $bo1 < 0 or $bo2 < 0 or $bo3 < 0 or $bo4 < 0 or $bo5 < 0 or $bo6 < 0 )
        { 
            $negativ = 1; 
            echo '<input type=hidden name=negativ value='. $negativ . ' />';
        }

        echo '<br />';
        echo '</div>';

        echo '<br />';
        if ( $action == '' )
        {
            echo '<input type="image" src="bilder/buttons/auffuellen.gif" class="right2" name="autofill" alt="Auff&uuml;llen" title=" Auff&uuml;llen " />'; 
        }

        if ( $action == 'fillitup' )
        {
            echo '<div class="textfield8">';
            echo "Auff&uuml;llen erfolgreich umgesetzt!";
            echo '</div>';
            echo '<input type="image" src="bilder/buttons/weiter.gif" class="marginleft3" name="next" alt="Weiter" title=" Weiter " />';
        }

    } } } }
	echo '</form>';
}

function autofill() {

    global $negativ,$zero,$savefillup,$bo1,$bo2,$bo3,$bo4,$bo5,$bo6,$modus,$saveselect1,$saveselect2,$saveselect3,$saveselect4,$saveselect5,$saveselect6,$saveresult1,$saveresult2,$saveresult3,$saveresult4,$saveresult5,$saveresult6;

    echo '<form name="yyy" action="auffuellen.html" method="post">';
    
    // if change and not actualized autofill(only for modus2 relevant);
    if ( $modus == 2 )
    {
    $resultconf = $bo1 + $bo2 + $bo3 + $bo4 + $bo5 + $bo6;
    $resultconf1 = $bo1;
    $resultconf2 = $bo2;
    $resultconf3 = $bo3;
    $resultconf4 = $bo4;
    $resultconf5 = $bo5;
    $resultconf6 = $bo6;

    if ( $negativ == 1 )
    {
        echo '<div class="textfield8" >Keine negativen Werte zul&auml;ssig!&nbsp;</div>';
        echo '<input type="image" src="bilder/buttons/abbrechen.gif" name="stop" alt="Abbrechen" title=" Abbrechen " />';
    }
    elseif ( $zero == 1 )
    {
        echo '<div class="textfield7" >Aufzuf&uuml;llende W&ouml;rter = 0 - kein Auff&uuml;llen m&ouml;glich!&nbsp;</div>';
        echo '<input type="image" src="bilder/buttons/abbrechen.gif" name="stop" alt="Abbrechen" title=" Abbrechen " />';
    }
    else
    {
    echo '<div class="textfield6" >Bitte best&auml;tige die Eingaben:&nbsp;</div>';
    echo '<div class="marginright4"><b>'. $resultconf . '</b></div>';
    echo '<div class="marginright4"><b>'. $bo1 . '</b></div>';
    echo '<div class="marginright4"><b>'. $bo2 . '</b></div>';
    echo '<div class="marginright4"><b>'. $bo3 . '</b></div>';
    echo '<div class="marginright4"><b>'. $bo4 . '</b></div>';
    echo '<div class="marginright4"><b>'. $bo5 . '</b></div>';
    echo '<div class="marginright4"><b>'. $bo6 . '</b></div>';
    }
    }
    elseif ( $modus == 1 )
    {
    
    if ( $zero == 1 )
    {
        echo '<div class="textfield7" >Aufzuf&uuml;llende W&ouml;rter = 0 - kein Auff&uuml;llen m&ouml;glich!&nbsp;</div>';
        echo '<input type="image" src="bilder/buttons/abbrechen.gif" name="stop" alt="Abbrechen" title=" Abbrechen " />';
    }
    else
    {
    $resultconf = $saveselect1 + $saveselect2 + $saveselect3 + $saveselect4 + $saveselect5 + $saveselect6;
    $resultconf1 = $saveselect1;
    $resultconf2 = $saveselect2;
    $resultconf3 = $saveselect3;
    $resultconf4 = $saveselect4;
    $resultconf5 = $saveselect5;
    $resultconf6 = $saveselect6;

    echo '<div class="textfield6" >Bitte best&auml;tige die Eingaben:&nbsp;</div>';
    echo '<div class="marginright4"><b>'. $resultconf . '</b></div>';
    echo '<div class="marginright4"><b>'. $saveselect1 . '</b></div>';
    echo '<div class="marginright4"><b>'. $saveselect2 . '</b></div>';
    echo '<div class="marginright4"><b>'. $saveselect3 . '</b></div>';
    echo '<div class="marginright4"><b>'. $saveselect4 . '</b></div>';
    echo '<div class="marginright4"><b>'. $saveselect5 . '</b></div>';
    echo '<div class="marginright4"><b>'. $saveselect6 . '</b></div>';
    }
    }
    echo '<br />';
    if ( $negativ == 0 and $zero == 0 )
    {
        echo '<div class="left2">&nbsp;</div>';
        echo '<input type="image" src="bilder/buttons/auffuellen.gif" class="margin1" name="confirm" alt="Auff&uuml;llen" title=" Auff&uuml;llen " />';
        echo '<input type="image" src="bilder/buttons/abbrechen.gif" class="margin1" name="stop" alt="Abbrechen" title=" Abbrechen " />';
    }

    // save results
    $select1 = $saveselect1;
    $select2 = $saveselect2;
    $select3 = $saveselect3;
    $select4 = $saveselect4;
    $select5 = $saveselect5;
    $select6 = $saveselect6;
    echo '<input type="hidden" name="saveselect1" value="'. $select1 . '" />';
    echo '<input type="hidden" name="saveselect2" value="'. $select2 . '" />';
    echo '<input type="hidden" name="saveselect3" value="'. $select3 . '" />';
    echo '<input type="hidden" name="saveselect4" value="'. $select4 . '" />';
    echo '<input type="hidden" name="saveselect5" value="'. $select5 . '" />';
    echo '<input type="hidden" name="saveselect6" value="'. $select6 . '" />';

    //save fillup, to see if fill-up-qty changed (see above)
    echo '<input type="hidden" name="savefillup" value="'. $savefillup . '" />';

    // save final results
    echo '<input type="hidden" name="resultconf1" value="'. $resultconf1 . '" />';
    echo '<input type="hidden" name="resultconf2" value="'. $resultconf2 . '" />';
    echo '<input type="hidden" name="resultconf3" value="'. $resultconf3 . '" />';
    echo '<input type="hidden" name="resultconf4" value="'. $resultconf4 . '" />';
    echo '<input type="hidden" name="resultconf5" value="'. $resultconf5 . '" />';
    echo '<input type="hidden" name="resultconf6" value="'. $resultconf6 . '" />';

    echo '<input type="hidden" name="modus" value="'. $modus . '" />';

    echo '</form>';

}

function fillitup() {

    global $num_rows,$customerid,$resultconf1,$resultconf2,$resultconf3,$resultconf4,$resultconf5,$resultconf6;

    require_once ('fuellauf.html');

}


function mysql_query_secure($query)
{
   $result=mysql_query($query);
   if ( ! $result ) { die('Error query : ' . mysql_error()); }
   return $result;
}


echo '</div>';
echo '</div>';
echo '<div id="adverts">';
echo '<div id="adbox"></div>';
echo '</div>';

require ('fuss.html');
?>

</body>
</html>